<template>
  <div class="home">
    <a-card :bordered="false">
      <!-- 表格顶部搜索部分 -->
      <c-table-search-form
        v-model="tableSearchForm"
        :datas="tableSearchFormData"
        @onSearch="onSearch"
      >
      </c-table-search-form>

      <!-- 表格部分 -->
      <c-table
        showPagination
        :columns="tableColumns"
        :datas="tableData"
        :loading="loading"
        :paginationDatas="paginationDatas"
        @onPageSizeChange="onPageSizeChange"
        @onShowNumChange="onShowNumChange"
      >
        <template slot="roleName" slot-scope="roleName">
          <a-tag>{{ roleName.tableRow }}</a-tag>
        </template>
        <template slot="companyStatus" slot-scope="companyStatus">
          <a-tag>{{ companyStatus.tableRow }}</a-tag>
        </template>
        <template slot="handle" slot-scope="row">
          <a @click="handleView(row.tableRow)"><a-icon type="eye" /> 查看</a>
        </template>
      </c-table>
    </a-card>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { getUserList } from "@/api/company/users";

export default {
  name: "users",
  components: {},
  data() {
    return {
      tableSearchForm: {
        searchKey: "",
        status: "1"
      },
      tableSearchFormData: [
        {
          label: "账户状态",
          prop: "status",
          type: "select",
          typeData: [
            {
              label: "全部",
              value: "0"
            },
            {
              label: "待审核",
              value: "1"
            },
            {
              label: "正常",
              value: "2"
            },
            {
              label: "已拒绝",
              value: "3"
            },
            {
              label: "待认证",
              value: "4"
            }
          ]
        },
        {
          label: "请输入企业名称/简称/用户手机号码/姓名",
          prop: "searchKey",
          type: "search"
        }
      ],
      tableColumns: [
        {
          title: "用户编号",
          dataIndex: "userId",
          width: "100",
          align: "center"
        },
        {
          title: "真实姓名",
          dataIndex: "userName",
          width: "100",
          align: "center"
        },
        {
          title: "手机号码",
          dataIndex: "userPhone",
          align: "center"
        },
        {
          title: "所属公司",
          dataIndex: "companyName",
          align: "center"
        },
        {
          title: "用户身份",
          dataIndex: "roleName",
          scopedSlots: { customRender: "roleName" },
          align: "center"
        },
        {
          title: "有效期",
          dataIndex: "validityDate",
          align: "center"
        },
        {
          title: "账户状态",
          dataIndex: "companyStatus",
          scopedSlots: { customRender: "companyStatus" },
          align: "center"
        },
        {
          title: "上次登录时间",
          dataIndex: "lastLoginDate",
          width: "200",
          align: "center"
        },
        {
          title: "操作",
          key: "handle",
          width: "100px",
          scopedSlots: { customRender: "handle" },
          align: "center"
        }
      ],
      tableData: [],
      paginationDatas: {
        pageSizeOptions: ["10", "20", "30", "40", "50","200","1000"],
        pageSize: 10,
        pageNum: 1,
        total: 0
      }
    };
  },
  computed: {
    ...mapState({})
  },
  created() {
    this.onPageOnlod();
  },
  mounted() {},
  methods: {
    onPageOnlod() {
      this.loading = true;
      getUserList({
        pageData: {
          ...{
            pageSize: this.paginationDatas.pageSize,
            pageNum: this.paginationDatas.pageNum
          }
        }
      })
        .then(res => {
          this.tableData = res.data.pageData;
          this.paginationDatas.total = res.data.total;
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    onShowNumChange(val) {
      this.paginationDatas.pageNum = val;
      this.onPageOnlod();
    },
    onPageSizeChange(val) {
      this.paginationDatas.pageSize = val;
      this.onPageOnlod();
    },
    onSearch() {},
    handleView(row) {
      this.$router.push({ name: "Company_Users_Detail" });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
